var dappAddress = "n1zAKhRRAfwr7zqafBhvpMcKHoWpyKAcQ4d";
var hash = "74a931bbe23c7c1abefb1f39bc8a800af68221e5f1b2eba99c50dbdb75ffaad3";
var NebPay = require("nebpay");
var nebPay = new NebPay();

$('input').on('blur', function () {
  $(this).removeClass('blur')
})

$('input').on('focus', function () {
  $(this).addClass('blur')
})

function getTime (data) {
  var myDate = new Date(+data);
  var year = myDate.getFullYear();
  var months = myDate.getMonth() + 1;
  var month = months.toString().length === 2 ? months : '0' + months;
  var date = myDate.getDate().toString().length === 2 ? myDate.getDate() : '0' + myDate.getDate();
  var hours = myDate.getHours().toString().length === 2 ? myDate.getHours() : '0' + myDate.getHours();
  var minutes = myDate.getMinutes().toString().length === 2 ? myDate.getMinutes() : '0' + myDate.getMinutes();
  var seconds = myDate.getSeconds().toString().length === 2 ? myDate.getSeconds() : '0' + myDate.getSeconds();
  return year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds
}


function init () {
  if (typeof nebPay.simulateCall == "undefined" || typeof nebPay.call == "undefined") {
    toast('检测到您未开启星云钱包插件,请启动并刷新页面。 如果您确认有开启,请刷新浏览器！');
    return
  }
}

function getWallectInfo () {
  window.postMessage({
    "target": "contentscript",
    "data": {},
    "method": "getAccount"
  }, "*");
  window.addEventListener("message", function (e) {
    if (e.data && e.data.data && e.data.data.account) {
      window.address = e.data.data.account;
      getAddressName && getAddressName(window.address);
    }
  })
}

$(function () {
  init();
  getWallectInfo();
})

function toast (text) {
  $('#toast').html(text);
  $('#toast').show();
  setTimeout(function () {
    $('#toast').addClass('toast-show');
    showToast()
  }, 300);
}

function showToast () {
  setTimeout(function () {
    $('#toast').removeClass('toast-show');
    setTimeout(function () {
      $('#toast').hide();
    }, 2300);
  }, 5000);
}